import time

from selenium.webdriver.common.by import By


class LoginOperation:

    def login(self, driver, name, pwd):
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)

        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)

        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(1)

    #  获取成功的实际结果
    def getSuccessResult(self, driver):
        return driver.find_element(By.XPATH, '//*[@id="logo"]/a').text

    # 获取用户名错误的实际结果
    def getNameErrorResult(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div/div/div/form/div[1]/span[1]').text

    # 获取密码错误的实际结果
    def getPwdErrorResult(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div/div/div/form/div[2]/span[1]').text
